import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class Main {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()) {
            test3(jedis);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void test1(Jedis jedis) {
        jedis.set("key", "你好");
        String string = jedis.get("key");
        String s = jedis.get("1");
        String mset = jedis.mset("key1", "value1", "key2", "value2");
        System.out.println(mset);
        System.out.println(jedis.exists("key2"));
        long key1 = jedis.del("key1");
        System.out.println(key1);
        Set<String> keys = jedis.keys("*");
        System.out.println(string + "\n" + s);
        System.out.println(keys);
    }

    public static void test2(Jedis jedis) throws InterruptedException {
        jedis.flushDB();
        jedis.set("key", "rht");
        jedis.expire("key", 5);
        System.out.println(jedis.get("key") + " " + jedis.ttl("key"));
        Thread.sleep(2500);
        System.out.println(jedis.get("key") + " " + jedis.ttl("key"));
        Thread.sleep(2500);
        System.out.println(jedis.get("key"));
    }

    public static void test3(Jedis jedis) {
        jedis.flushDB();
        jedis.set("key", "1");
        jedis.hset("HKey", "filed", "xyz");
        jedis.sadd("SKey", "abc", "2");
        jedis.incr("key");
        jedis.lpush("rht", "2004", "0702");
        System.out.println(jedis.get("key") + " " + jedis.hget("HKey", "filed")
               + " " + jedis.srandmember("SKey") + " " + jedis.rpop("rht"));
        System.out.println(jedis.type("key") + "\n" + jedis.type("HKey") +
                "\n" + jedis.type("SKey") + jedis.type("rht"));
    }
}
